package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorSecckill;
import guoanmaker.operator.business.modelnobind.ActivityInfor;
import guoanmaker.operator.business.modelnobind.SecckillAndCommodMove;
import guoanmaker.operator.business.modelnobind.SecckillMove;
import guoanmaker.operator.business.service.OperatorSecckillServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

/**
 *  
 *
 * @author wanghongwei 
 * @ClassName: OperatorSecckillController
 * @Description: OperatorSecckillController 
 * @date 2017/11/21 下午15:05
 */
@RestController
@RequestMapping(ApiController.OPERATOR_SECCKILL)
public class OperatorSecckillController {
	private final AjaxJson ajaxJson;
	private final OperatorSecckillServiceInterface operatorSecckillServiceInterface;
	
	public OperatorSecckillController(AjaxJson ajaxJson,OperatorSecckillServiceInterface  operatorSecckillServiceInterface){
		this.ajaxJson=ajaxJson;
		this.operatorSecckillServiceInterface=operatorSecckillServiceInterface;
	}

	/**
	 * @Title: saveOperatorSecckill
	 * @Description: 添加秒杀信息
	 * @param: OperatorSecckill  
	 * @return AjaxJson    
	 * @throws 
	 */
	@ApiOperation(value = "添加秒杀信息", notes = "添加秒杀信息")
	@PostMapping(value = "saveOperatorSecckill")
	public AjaxJson saveOperatorSecckill(@RequestBody OperatorSecckill operatorSecckill) {
		return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSecckillServiceInterface.saveOperatorSecckill(operatorSecckill));
	}

	/**
	 * @Title: selectProvideCommodityByCode
	 * @Description: 添加秒杀信息
	 * @param: CommodityMove  
	 * @return AjaxJson    
	 * @throws 
	 */
	@ApiOperation(value = "根据商品编号查询寻信息", notes = "根据商品编号查询寻信息")
	@PostMapping(value = "selectProvideCommodityByCode")
	public AjaxJson selectProvideCommodityByCode(@RequestParam Integer commodCode) {
		return ajaxJson.setSuccess(true).setStatus(200).setData(operatorSecckillServiceInterface.selectProvideCommodityByCode(commodCode));
	}
	
	/**
	 * @Title: deleteOperatorSecckillById
	 * @Description : 删除秒杀信息
	 * @param: OperatorSecckill  
	 * @return AjaxJson    
	 * @throws 
	 */
	@ApiOperation(value = "根据秒杀id删除秒杀信息", notes = "根据秒杀id删除秒杀信息")
	@PostMapping(value = "deleteOperatorSecckillById")
	public AjaxJson deleteOperatorSecckillById(@RequestParam String secckillId) {
		operatorSecckillServiceInterface.deleteOperatorSecckillById(secckillId);
		return ajaxJson.setSuccess(true).setStatus(200).setData(null);
	}
	/**
	 * @Title: deleteOperatorSecckillByTime
	 * @Description : 删除秒杀区间信息
	 * @param: OperatorSecckill  
	 * @return AjaxJson    
	 * @throws 
	 */
	@ApiOperation(value = "根据秒杀时间 删除秒杀信息", notes = "根据秒杀时间 删除秒杀信息")
	@PostMapping(value = "deleteOperatorSecckillByTime")
	public AjaxJson deleteOperatorSecckillByTime(@RequestParam String startTime) {
		operatorSecckillServiceInterface.deleteOperatorSecckillByTime(startTime);
		return ajaxJson.setSuccess(true).setStatus(200).setData(null);
	}
	
	@ApiOperation(value = "根据活动查询秒杀时间信息", notes = "根据活动查询秒杀时间信息")
	@PostMapping(value = "selectSecckillByActivityId")
	public AjaxJson selectSecckillByActivityId(@RequestParam String activityId) {
		ActivityInfor activityInfor= operatorSecckillServiceInterface.selectSecckillByActivityId(activityId);
		return ajaxJson.setSuccess(true).setStatus(200).setData(activityInfor);
	}
	
	/**
	 * @Title: selectSecckillByDate
	 * @Description : 根据时间查询秒杀信息
	 * @param: OperatorSecckill  
	 * @return AjaxJson    
	 * @throws 
	 */
	@ApiOperation(value = "根据时间查询秒杀信息", notes = "根据时间查询秒杀信息")
	@PostMapping(value = "selectSecckillByDate")
	public AjaxJson selectSecckillByDate(@RequestParam String activityId ,String skStartTime ) {//@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
		List<SecckillAndCommodMove> SecckillAndCommodList= operatorSecckillServiceInterface.selectSecckillByDate(activityId,skStartTime);
		return ajaxJson.setSuccess(true).setStatus(200).setData(SecckillAndCommodList);
	}
	
	
	
}
